package cn.autumnorange.app.money.consumer.controller;

import cn.autumnorange.app.common.dto.ResultDto;
import cn.autumnorange.app.money.api.MoneyService2;
import cn.autumnorange.app.money.api.dto.MoneyDto;
import com.taobao.txc.client.aop.annotation.TxcTransaction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class MoneyController2 implements MoneyService2 {
  @Autowired MoneyService2 moneyService2;

  @TxcTransaction(timeout = 60000 * 5)
  @Override
  public ResponseEntity<ResultDto<MoneyDto>> add2(
      @PathVariable(value = "version") Long version, @PathVariable(value = "money") Long money) {
    ResponseEntity<ResultDto<MoneyDto>> resultDto = moneyService2.add2(version, money);

    if (resultDto == null || resultDto.getStatusCodeValue() != HttpStatus.OK.value()) {
      throw new RuntimeException(resultDto.getBody().getMessage());
    }
    return resultDto;
  }

  public ResponseEntity<ResultDto<Long>> getVersion(@PathVariable(value = "id") Long id) {
    return null;
  }
}
